
public class ContainerWithMostWater {
	public static int maxArea1(int[] height) {
		if(height.length <= 1){return 0;}
		int maxArea = 0;
		for(int i = 1;i < height.length;i++){
			if(height[i-1] == 0){
				continue;
			}
			for(int j = i + 1; j <= height.length; j++){
				if(height[j-1] == 0){
					continue;
				}
				int min = (height[i-1] > height[j-1]) ? height[j-1] : height[i-1];
				int area = min * (j - i);
				if(area > maxArea){
					maxArea = area;
				}
			}
			
		}
        return maxArea;
    }
	public static int maxArea2(int[] height){
		if(height.length <= 1){return 0;}
		int maxArea = 0;
		int i = 1;
		int j = height.length;
		int tmpArea;
		while(i < j){
			tmpArea = (j - i) * ((height[i-1] > height[j-1]) ? height[j-1] : height[i-1]);
			if(height[i-1] > height[j-1]){
				j--;
			}else{
				i++;
			}
			if(maxArea < tmpArea){
				maxArea = tmpArea;
			}
		}
		return maxArea;
	}
	public static void main(String[] args){
		int[] height = new int[]{1,2,3,4,5};
		System.out.println(maxArea1(height));
	}
}
